#ifndef __HDVB_CHANSCANTODB_H
#define __HDVB_CHANSCANTODB_H
/*
    libhdvbd - Library for building sophisticated DVB applications
    Copyright (C) 2012 Tony Houghton <h@realh.co.uk>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/* Connects to an HdvbChannelScan's signals to add data to a database.
 * Automatically frees itself on cancelled or completed signals but you still
 * have to start the scanner after calling hdvb_chan_scan_to_db().
 */

#include <glib.h>

#include <sqlite3.h>

#include <hdvb/hdvb-channel-scan.h>

G_BEGIN_DECLS

typedef struct _HdvbChanScanToDb HdvbChanScanToDb;

struct _HdvbChanScanToDb {
    HdvbChannelScan *scanner;
    sqlite3 *db;
    sqlite3_stmt *service_stmt;
    sqlite3_stmt *transport_stmt;
    sqlite3_stmt *lcn_stmt;
    sqlite3_stmt *dvbt2_stmt;
    sqlite3_stmt *lookup_dvbt2_stmt;
    sqlite3_stmt *update_dvbt2_stmt;
    gulong service_tag, transport_tag, lcn_tag, dvbt2_tag, new_ts_tag;
    gulong cancelled_tag, completed_tag;
    void (*del)(HdvbChanScanToDb *);
    GArray *t2_ids;
};


/* Creates a new scanner and calls init */
HdvbChanScanToDb *
hdvb_chan_scan_to_db_new(sqlite3 *db, const char *factory);

/* The following are exposed for specialised versions to chain up */

gboolean
hdvb_chan_scan_to_db_init(HdvbChanScanToDb *cs2db,
        sqlite3 *db, const char *factory);

/* The db is left intact */
void
hdvb_chan_scan_to_db_standard_delete(HdvbChanScanToDb *cs2db);

G_END_DECLS

#endif /* __HDVB_CHANSCANTODB_H */
